package com.yunji.storage.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.constant.LogicCode;
import com.yunji.common.enums.business.StorageStatus;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.storage.bo.StorageTicketListQueryBO;
import com.yunji.storage.bo.StorageTicketSelectQueryBO;
import com.yunji.storage.dao.IStorageTicketDao;
import com.yunji.storage.domain.StorageTicketDO;
import com.yunji.storage.mapper.StorageTicketMapper;
import org.springframework.stereotype.Repository;

import java.util.Arrays;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.storage.dao.impl
 * @Title: StorageTicketDaoImpl
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-10-31 17:55:59      V1.0        HuaAo       新建类
 */
@Repository
public class StorageTicketDaoImpl extends BaseDaoImpl<StorageTicketMapper, StorageTicketDO> implements IStorageTicketDao {

    @Override
    public boolean updateStatus(StorageTicketDO ticket) {
        return update(null, new LambdaUpdateWrapper<StorageTicketDO>()
                .set(StorageTicketDO::getStorageStatus, ticket.getStorageStatus())
                .eq(StorageTicketDO::getBusinessType, ticket.getBusinessType())
                .eq(StorageTicketDO::getBusinessCode, ticket.getBusinessCode()));
    }

    @Override
    public StorageTicketDO select(StorageTicketSelectQueryBO bo) {
        return getOne(new LambdaQueryWrapper<StorageTicketDO>()
                .eq(BeanUtils.isNotNull(bo.getBusinessId()), StorageTicketDO::getBusinessId, bo.getBusinessId())
                .eq(BeanUtils.isNotNull(bo.getBusinessCode()), StorageTicketDO::getBusinessCode, bo.getBusinessCode())
                .eq(BeanUtils.isNotNull(bo.getStorageType()), StorageTicketDO::getStorageType, bo.getStorageType()));
    }

    @Override
    public boolean delete(Long... ticketIds) {
        return remove(new LambdaQueryWrapper<StorageTicketDO>()
                .in(StorageTicketDO::getTicketId, Arrays.asList(ticketIds))
                .eq(StorageTicketDO::getDeletable, LogicCode.YES));
    }

    @Override
    public List<StorageTicketDO> search(StorageTicketListQueryBO bo) {
        return list(new LambdaQueryWrapper<StorageTicketDO>()
                .eq(BeanUtils.isNotNull(bo.getBusinessId()),StorageTicketDO::getBusinessId,bo.getBusinessId())
                .eq(BeanUtils.isNotNull(bo.getStorageType()),StorageTicketDO::getStorageType,bo.getStorageType()));
    }
}